<?php
/**
 * 接口用户模型
 * @author sundongdong
 * @date 2016-07-12
 */
class Interface_Model_User extends Model_Base {
	/**
	 * 添加用户
	 * @param array $data
	 */
	public function add(array $data) {
		try {
			$this->db('write_db')->insert('s_user', $data);
		} catch (Exception $e) {
			return array('opr'=>0,'content'=>$e->getMessage());
		}
	}
	/**
	 * 用户是否存在检查
	 * @param string $username
	 */
	public function exist($username = '') {
		return $this->db()->fetchOne("select user_id from s_user where user_name = :user_name", array('user_name'=>$username));
	}
	/**
	 * 更新用户信息
	 * @param array $data
	 * @param number $user_id
	 */
	public function update(array $data, $user_id=0) {
		try {
			$where = $this->db('write_db')->quote('user_id=?', $user_id);
			$this->db('write_db')->update('s_user', $data, $where);
		} catch (Exception $e) {
			return array('opr'=>0,'content'=>$e->getMessage());
		}
	}
	/**
	 * 删除用户
	 * @param string $username
	 */
	public function delete($username = '') {
		try {
			$where = $this->db('write_db')->quote('user_name=?', $username);
			$this->db('write_db')->update('s_user', array('is_enable'=>0), 'user_name='.$where);
			return array('opr'=>1,'content'=>'删除成功');
		} catch (Exception $e) {
			return array('opr'=>0,'content'=>$e->getMessage());
		}
	}
}